//============================================================================
// Name        : LCS.cpp
// Author      : yu
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include "FileProcessor.cpp"
#include <iostream>
#include<fstream>
#include<vector>
#include "LCS.h"
using namespace std;
using namespace com_hcx;
char * getInputData(const string fileName,char *X,char *Y,int *x_len,int *y_len)
{
	FileProcessor fp;
	vector<char> data;
	bool isX = true;//true表示存入X，否则存入Y
	fp.getdata(fileName,data);

	for(vector<char>::size_type i=0; i!= data.size(); i++)
	{
		if(data[i]!=',')
		{
			if(isX)
			{
				X[++(*x_len)] = data[i];
				if(i+1<data.size() && data[i+1]!=',')
				{
					isX = false;
				}
			}
			else if(!isX)
			{
				Y[++(*y_len)] = data[i];
			}
		}
	}
}
void outputData(const vector<char> lcs_data,const string filename)
{
	FileProcessor fp;
	if(lcs_data.size()==0)
		fp.output_data(filename,"null");
	else
		fp.output_data(filename,lcs_data);
}
int main()
{
	LCS lcs;
	int x_len = 0;
	int y_len = 0;
	char X[MAXLEN]={'e'};
	char Y[MAXLEN]={'4'};
    vector<char> lcs_data;
	int longest_len[MAXLEN][MAXLEN];
	int b_way[MAXLEN][MAXLEN];
	getInputData("input.txt",X,Y,&x_len,&y_len);

	lcs.LCSLength(x_len,y_len,X,Y,longest_len);
	lcs.getLCS(x_len,y_len,X,Y,longest_len,lcs_data);
	outputData(lcs_data,"output.txt");
	return 0;
}

